package com.ruifu.common.utils;

import com.ruifu.common.po.PmPtMain;

import java.util.Comparator;

/**
 * @author nyr
 * @create 2019/8/27
 */
public class PtOrderComparator implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        PmPtMain o11 = (PmPtMain) o1;
        PmPtMain o21 = (PmPtMain) o2;
        if (o11.getPtOrder() == null || o21.getPtOrder() == null) {
            return -1;
        }
        String[] temp1 = o11.getPtOrder().split("\\.");
        String[] temp2 = o21.getPtOrder().split("\\.");
        String[] str1;
        String[] str2;
        if (temp1.length > temp2.length) {
            str2 = temp1;
            str1 = temp2;
        } else {
            str1 = temp2;
            str2 = temp1;
        }
        for (int i = 0; i < str2.length; i++) {
            if (i <= (str1.length - 1)) {
                if (Long.valueOf(str2[i]) > Long.valueOf(str1[i])) {
                    return 1;
                } else if (Long.valueOf(str2[i]) < Long.valueOf(str1[i])) {
                    return -1;
                } else {
                    continue;
                }
            } else {
                return 1;
            }
        }
        return 0;
    }
}

